---
title: "Geo-political Threat Index"
author: "Kohei Watanabe"
date: "`r format(Sys.time(), '%Y-%m-%d')`"
output: html_document
---

```{r, message=FALSE}
knitr::opts_chunk$set(echo = TRUE, dpi = 150)
require(lubridate)
source("functions.R")
dat <- readRDS("data_index.RDS")
event <- yaml::read_yaml("events.yml")
```

## Individual countries

```{r fig.height=6, fig.width=12}
plot_gti(dat, c("ru", "cn"), event)
```
    
```{r fig.height=6, fig.width=12}
plot_gti(dat, c("jp", "de"), event)
```

```{r fig.height=6, fig.width=12}
plot_gti(dat, c("fr", "gb"), event)
```

```{r fig.height=6, fig.width=12}
plot_gti(dat, c("ir", "iq", "af", "sy", "vn"), event)
```

```{r fig.height=6, fig.width=12}
plot_gti(dat, c("ca", "mx", "cu"), event)
```


## All countries

```{r}
dat_global <- readRDS("data_index_global.RDS")
length(unique(dat_global$country))
dat_globa_agg <- aggregate(gti ~ year, dat_global, FUN = sum)
mean(subset(dat_globa_agg, year %in% 1861:1913)$gti)
sd(subset(dat_globa_agg, year %in% 1861:1913)$gti)
mean(subset(dat_globa_agg, year %in% 1950:1991)$gti)
sd(subset(dat_globa_agg, year %in% 1950:1991)$gti)
```

```{r fig.height=6, fig.width=12}
plot_gti(dat_global, NULL,
         event, sum = TRUE, min_y = 0.3, max_y = 0.8, nudge_y = 0.07) +
         theme(legend.position = "none")
```
